import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    id:localStorage.getItem('id')?localStorage.getItem('id'):null,
    user: localStorage.getItem('user')?localStorage.getItem('user'):null,
    token:localStorage.getItem('token')?localStorage.getItem('token'):null,
  },
  mutations: {
    _setItem (state,e) {
      state.id =e.id,
      state.user =e.user,
      state.token =e.token,
      localStorage.setItem('id',e.id);
      localStorage.setItem('user',e.user);
      localStorage.setItem('token',e.token);
    },
    _getItem (state) {
      state.id =localStorage.getItem('id')
      state.user =localStorage.getItem('user')
      state.token =localStorage.getItem('token')
    },
    _removeItem (state) {
      localStorage.removeItem('id'),
      localStorage.removeItem('user')
      localStorage.removeItem('token')
      state.id =null;
      state.user =null;
      state.token =null;
      location.reload();
    }
  },
})

export default store